package com.elong.businesstravel.modules.home.adapter;

import java.util.List;

import com.elong.businesstravel.R;
import com.elong.businesstravel.entitys.Hotel;
import com.elong.businesstravel.entitys.HotelDocs;
import com.elong.businesstravel.entitys.HotelSearchCondition;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

/**
 * 头部添加可抵扣酒店的adapter
 * 
 * @author lenovo
 * 
 */
public class HeadHotelSearchResultAdapter extends HotelSearchResultAdapter {

	private static final String HEAD = "head";
	private static final String ITEM = "item";
	
	private Hotel mHotel;

	public HeadHotelSearchResultAdapter(Context context,
			List<HotelDocs> hotelList, HotelSearchCondition currentCondition, Hotel hotel) {
		super(context, hotelList, currentCondition);
		
		mHotel = hotel;
	}

	@Override
	public int getCount() {
		return super.getCount() + 1;
	}

	@Override
	public Object getItem(int position) {
		if (0 == position) {
			return "";
		}
		return super.getItem(position - 1);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (null == convertView) {
			if (0 == position) {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.view_head_hotel_search_result, null);
				convertView.setTag(HEAD);
			} else if (0 != position) {
				int tempPosition = position - 1;
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.adapter_hotel_search_result, null);
//				convertView = super.getView(tempPosition, convertView, parent);
				convertView.setTag(ITEM);
			}
		} else {
			if (0 == position && !HEAD.equals(convertView.getTag())) {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.view_head_hotel_search_result, null);
				convertView.setTag(HEAD);
			} else if (0 != position && !ITEM.equals(convertView.getTag())) {
				int tempPosition = position - 1;
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.adapter_hotel_search_result, null);
//				convertView = super.getView(tempPosition, convertView, parent);
				convertView.setTag(ITEM);
			}
		}
		
		//设置数据
		if (0 == position && HEAD.equals(convertView.getTag())) {
			TextView hotelNumTextView = (TextView)convertView.findViewById(R.id.hotelNumTextView);
			hotelNumTextView.setText(mHotel.prehotel);
		}else if(0 != position && ITEM.equals(convertView.getTag())){
			int tempPosition = position - 1;
			convertView = super.getView(tempPosition, convertView, parent);
		}

		return convertView;
	}
}
